package com.shigen.demo.base;

import java.io.Serializable;
import java.util.Collection;

/**
 * lambda表达式demo
 *
 * @author shigenfu
 * @date 2022/12/2 19:01
 */
public class LambdaDemo<T extends Serializable & Comparable & Collection> {


  interface MathOperation<T> {

    T operation(int a, int b);
  }

  // <T> 强制返回类型的转换
  private <T> T operate(int a, int b, MathOperation<T> mathOperation) {
    return mathOperation.operation(a, b);
  }


  public static void main(String[] args) {
    LambdaDemo demo = new LambdaDemo();
    MathOperation<Integer> operation = new MathOperation<Integer>() {
      @Override
      public Integer operation(int a, int b) {
        return a + b;
      }
    };
    MathOperation devide = (a, b) -> a / b;
    System.out.println(demo.operate(10, 5, operation));
    System.out.println(demo.operate(10, 100, devide));
    demo.operate(10, 20, (a, b) -> Math.pow(a, b));

  }

}
